async function getKong(classId, day, school, week, enforce) {
	var [err, res] = await uni.request({
		url: 'http://211.82.48.36/'
	})
	if (res.data.indexOf("URP综合教务系统首页") == -1) return null

	let arr = [
		['主楼', '阶教', '操场', '大数据', '矿山压力', '力学楼', '煤矿基地', '实1', '实2', '实3', '实习工厂', '图书馆', '行知楼'],
		['2号教学楼', '办公楼', '操场', '机房', '教学楼', '阶梯']
	];

	let teaNum = arr[school][classId];

	let classAll = new Array(4);
	let roomMap = new Map();
	let roomCheck = [];
	let cnt = 0;

	for (let course = 1; course <= 5; course++) {
		classAll[course - 1] = await getClassArr(week, school, teaNum, day, 2 * course - 1);
	}

	

	async function getClassArr(week, school, teaNum, day, course) {
		school += 1
		let subArr = []
		let url = "http://211.82.48.36/student/teachingResources/freeClassroomQuery/search"
		var [err, res] = await uni.request({
			url: url,
			method: 'POST',
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			},
			data: {
				weeks: week,
				jslxdm: '',
				codeCampusListNumber: "00" + school,
				teaNum: teaNum,
				wSection: day + '/' + course + ',' + day + '/' + (course + 1),
				pageNum: 1,
				pageSize: 100,

			}
		});

		if (!Array.isArray(res.data)) return null
		let content = res.data
		let total =
			content[0]['pageContext']['totalCount'];
		let list0 =
			content[0]['records'];

		if (Array.isArray(list0)) {
			for (let i = 0; i < list0.length; i++) {
				let value0 = list0[i]
				let classroomName =
					value0['classroomName'];
				subArr.push(addCheck(classroomName))
			}
		}

		let endpage = Math.ceil(total / 100);

		for (let i = 2; i <= endpage; i++) {
			var [err, res] = await uni.request({
				url: url,
				method: 'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				data: {
					weeks: week,
					jslxdm: '',
					codeCampusListNumber: "00" + school,
					teaNum: teaNum,
					wSection: day + '/' + course + ',' + day + '/' + (course + 1),
					pageNum: i,
					pageSize: 100,

				}
			});

			content = res.data
			list0 =
				content[0]['records'];

			if (Array.isArray(list0)) {
				for (let i = 0; i < list0.length; i++) {
					let value0 = list0[i]
					let classroomName =
						value0['classroomName'];
					subArr.push(addCheck(classroomName))
				}
			}

		}
		
		return subArr;
	}

	function addCheck(room) {
		let t = roomMap.get(room);
		if (t == undefined) {
			roomMap.set(room, cnt);
			t = cnt;
			roomCheck.push(false);
			cnt += 1;
		}
		
		return [room, t];
	}
	let uptime = new Date().getTime()

	return {
		classAllArr: classAll,
		roomCheck,
		uptime
	}
}


export {
	getKong
}
